<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="机构名称" prop="institutionname">
      <el-input v-model="dataForm.institutionname" placeholder="机构名称"></el-input>
    </el-form-item>
    <el-form-item label="机构类型" prop="institutiontype">
      <el-input v-model="dataForm.institutiontype" placeholder="机构类型"></el-input>
    </el-form-item>
    <el-form-item label="机构状态" prop="institutionstatus">
      <el-input v-model="dataForm.institutionstatus" placeholder="机构状态"></el-input>
    </el-form-item>
    <el-form-item label="机构级别" prop="institutionlevel">
      <el-input v-model="dataForm.institutionlevel" placeholder="机构级别"></el-input>
    </el-form-item>
    <el-form-item label="省份" prop="province">
      <el-input v-model="dataForm.province" placeholder="省份"></el-input>
    </el-form-item>
    <el-form-item label="市" prop="city">
      <el-input v-model="dataForm.city" placeholder="市"></el-input>
    </el-form-item>
    <el-form-item label="负责人" prop="director">
      <el-input v-model="dataForm.director" placeholder="负责人"></el-input>
    </el-form-item>
    <el-form-item label="联系人" prop="contacts">
      <el-input v-model="dataForm.contacts" placeholder="联系人"></el-input>
    </el-form-item>
    <el-form-item label="日志所属人" prop="logowner">
      <el-input v-model="dataForm.logowner" placeholder="日志所属人"></el-input>
    </el-form-item>
    <el-form-item label="日志日期" prop="logdate">
      <el-input v-model="dataForm.logdate" placeholder="日志日期"></el-input>
    </el-form-item>
    <el-form-item label="日志等级" prop="loglevel">
      <el-input v-model="dataForm.loglevel" placeholder="日志等级"></el-input>
    </el-form-item>
    <el-form-item label="日志内容" prop="logcontent">
      <el-input v-model="dataForm.logcontent" placeholder="日志内容"></el-input>
    </el-form-item>
    <el-form-item label="购买产品类别" prop="purchaseproductcategory">
      <el-input v-model="dataForm.purchaseproductcategory" placeholder="购买产品类别"></el-input>
    </el-form-item>
    <el-form-item label="产品状态" prop="productstatus">
      <el-input v-model="dataForm.productstatus" placeholder="产品状态"></el-input>
    </el-form-item>
    <el-form-item label="审核状态" prop="auditstatus">
      <el-input v-model="dataForm.auditstatus" placeholder="审核状态"></el-input>
    </el-form-item>
    <el-form-item label="机构编号" prop="institutionid">
      <el-input v-model="dataForm.institutionid" placeholder="机构编号"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          institutionname: '',
          institutiontype: '',
          institutionstatus: '',
          institutionlevel: '',
          province: '',
          city: '',
          director: '',
          contacts: '',
          logowner: '',
          logdate: '',
          loglevel: '',
          logcontent: '',
          purchaseproductcategory: '',
          productstatus: '',
          auditstatus: '',
          institutionid: ''
        },
        dataRule: {
          institutionname: [
            { required: true, message: '机构名称不能为空', trigger: 'blur' }
          ],
          institutiontype: [
            { required: true, message: '机构类型不能为空', trigger: 'blur' }
          ],
          institutionstatus: [
            { required: true, message: '机构状态不能为空', trigger: 'blur' }
          ],
          institutionlevel: [
            { required: true, message: '机构级别不能为空', trigger: 'blur' }
          ],
          province: [
            { required: true, message: '省份不能为空', trigger: 'blur' }
          ],
          city: [
            { required: true, message: '市不能为空', trigger: 'blur' }
          ],
          director: [
            { required: true, message: '负责人不能为空', trigger: 'blur' }
          ],
          contacts: [
            { required: true, message: '联系人不能为空', trigger: 'blur' }
          ],
          logowner: [
            { required: true, message: '日志所属人不能为空', trigger: 'blur' }
          ],
          logdate: [
            { required: true, message: '日志日期不能为空', trigger: 'blur' }
          ],
          loglevel: [
            { required: true, message: '日志等级不能为空', trigger: 'blur' }
          ],
          logcontent: [
            { required: true, message: '日志内容不能为空', trigger: 'blur' }
          ],
          purchaseproductcategory: [
            { required: true, message: '购买产品类别不能为空', trigger: 'blur' }
          ],
          productstatus: [
            { required: true, message: '产品状态不能为空', trigger: 'blur' }
          ],
          auditstatus: [
            { required: true, message: '审核状态不能为空', trigger: 'blur' }
          ],
          institutionid: [
            { required: true, message: '机构编号不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/com/logmanagement/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.institutionname = data.logmanagement.institutionname
                this.dataForm.institutiontype = data.logmanagement.institutiontype
                this.dataForm.institutionstatus = data.logmanagement.institutionstatus
                this.dataForm.institutionlevel = data.logmanagement.institutionlevel
                this.dataForm.province = data.logmanagement.province
                this.dataForm.city = data.logmanagement.city
                this.dataForm.director = data.logmanagement.director
                this.dataForm.contacts = data.logmanagement.contacts
                this.dataForm.logowner = data.logmanagement.logowner
                this.dataForm.logdate = data.logmanagement.logdate
                this.dataForm.loglevel = data.logmanagement.loglevel
                this.dataForm.logcontent = data.logmanagement.logcontent
                this.dataForm.purchaseproductcategory = data.logmanagement.purchaseproductcategory
                this.dataForm.productstatus = data.logmanagement.productstatus
                this.dataForm.auditstatus = data.logmanagement.auditstatus
                this.dataForm.institutionid = data.logmanagement.institutionid
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/com/logmanagement/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'institutionname': this.dataForm.institutionname,
                'institutiontype': this.dataForm.institutiontype,
                'institutionstatus': this.dataForm.institutionstatus,
                'institutionlevel': this.dataForm.institutionlevel,
                'province': this.dataForm.province,
                'city': this.dataForm.city,
                'director': this.dataForm.director,
                'contacts': this.dataForm.contacts,
                'logowner': this.dataForm.logowner,
                'logdate': this.dataForm.logdate,
                'loglevel': this.dataForm.loglevel,
                'logcontent': this.dataForm.logcontent,
                'purchaseproductcategory': this.dataForm.purchaseproductcategory,
                'productstatus': this.dataForm.productstatus,
                'auditstatus': this.dataForm.auditstatus,
                'institutionid': this.dataForm.institutionid
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
